/* 
 * SourceServImpl.java 
 * 
 * Copyright 2009 Handlewell Beijing Inc. 
 * All rights reserved. 
 * 
 * Created on 2009-8-24 
 */
package com.handlewell.generator.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.handlewell.generator.service.ISourceServ;
import com.handlewell.generator.support.TableColumns;
import com.handlewell.generator.support.VelocityUtil;

/**
 * 功能概述： <br>
 * 
 * @author 倪敏
 * 
 */
public class SourceServImpl implements ISourceServ {
	private VelocityUtil velocityUtil;
	
	
	public void initService(HashMap<String,String> props, List<TableColumns> columnList, VelocityUtil velocityUtil){
		// TODO Auto-generated method stub
		this.velocityUtil = velocityUtil;
		
		// 添加配置信息到Velocity容器中(根据传入的props)
		Iterator<String> itr=props.keySet().iterator();
		while(itr.hasNext()){
			String key=itr.next();
			velocityUtil.put(key,props.get(key));
		}
		velocityUtil.put("Date", (new SimpleDateFormat("yyyy-MM-dd")).format(new Date()));
		velocityUtil.put("list", columnList);	
	}
	
	
	public void generate(String file_template,String file_path,String file_name)throws Exception {
		// TODO Auto-generated method stub
		velocityUtil.setTemplate(file_template,"UTF-8");
		velocityUtil.toFile(file_path, file_name);
	}
}
